<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
   
    <home-page></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./axios.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
    });
    const HomePage = {
      template: `
        <div>
          <ul>
            <li v-for="cate in cates" :key="cate.id">
              <img width="50" :src="cate.icon"/>  
              <h4>{{cate.name}}</h4>
            </li>  
          </ul>
        </div>
      `,
      
      data() {
        return {
          cates: [], // 1data中要定义初始值
        }
      },
      methods: {
        // 2 methods定义方法请求接口
          fetchCates(){
            /* axios.get('https://api.it120.cc/conner/cms/category/list?a=10&b=20').then(res => {
              if (res.data.code === 0) {
                this.cates = res.data.data
              }
            }) */
            axios.get('https://api.it120.cc/conner/cms/category/list', {
              params: {
                a: 10,
                b: 100
              }
            }).then(res => {
              if (res.data.code === 0) {
                this.cates = res.data.data
              }
            })
          }
      },
      created () {
        // 3 在合适生命周期钩子中调用
        this.fetchCates()
      } 
    }

    app.component('HomePage', HomePage)
    app.mount('#app')
  </script>
</body>
</html>